package com.ecar.api.rest.driver;

import java.util.List;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ecar.api.rest.AbstractResource;
import com.ecar.api.service.driver.CarService;
import com.ecar.common.annotation.ResponseFilter;
import com.ecar.common.dto.DataBean;
import com.ecar.core.driver.entity.Car;
import com.ecar.core.driver.entity.RecommendCar;

import net.sf.json.JSONObject;

/**
 * 类CarController.java的实现描述：实现车辆相关业务处理
 * 
 * @author fire 
 */
@Controller
@Scope("prototype")
@Path("/car")
public class CarController extends AbstractResource{
	
	
	@Autowired
	CarService carService;
	
	/**
	 * 获取车辆信息
	 * @author fire
	 * @param phone
	 * @return
	 */
	@ResponseFilter(target = Car.class, fields = {})
	@GET
	@Path("/{driverId}/getInfo")
	@Produces(MediaType.APPLICATION_JSON)
	public DataBean getCarInfo(@PathParam("driverId")String driverId) {
		return carService.selectByDriverId(driverId);
	}
	
	/**
	 * 获取车辆信息
	 * @author fire
	 * @param phone
	 * @return
	 */
	@GET
	@Path("/cartype")
	@Produces(MediaType.APPLICATION_JSON)
	public DataBean getCarType() {
		try {
			List<Object> list = carService.selectAllCarType();
			return new DataBean(200, list, "查询成功返回车辆类型信息");
		} catch (Exception e) {
			e.printStackTrace();
			return new DataBean(500, new JSONObject(), "服务器异常!");
		}
	}
	
	
	/**
	 * 获取推存车辆信息
	 * @author paul
	 * @return
	 */
	@GET
	@Path("/recommendCar")
	@Produces(MediaType.APPLICATION_JSON)
	public DataBean getreCommendCar() {
		try {
			List<RecommendCar> list = carService.selectAllRecommendCar();
			return new DataBean(200, list, "查询推存车辆信息成功！");
		} catch (Exception e) {
			e.printStackTrace();
			return new DataBean(500, new JSONObject(), "服务器异常!");
		}
	}
}
